<?php
class ConfartAction extends Action {
	
	public function index(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$model=D('Confart');
		$list=$model->select();
		$this->assign('list',$list);
		$this->display();
	}
	
	public function addconfart(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		if($_POST){
			$cond = $_POST;
			$cond['_column'] = array('artitle','arcontent');
			foreach ($cond['_column'] as $one) $data[$one] = trim($cond[$one]);
			$confart = D("Confart");
			if($confart->create($data))
			{
				if(($uid = $confart->add()) != false)
				{
					$this->redirect('Confart/index');
				}
			}else
			{
				$this->assign('erorsta','1');
				$this->assign('error',$confart->getError());
			}
		}
		$this->display();
	}
	
	public function edit(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$fid['arid']=$_GET['arid'];
	    $model=D('Confart');
	    $data=$model->where($fid)->find();
	    $this->assign('data',$data);
		if($_POST){
			$confart = D("Confart");
			$datas = array(
				"arid"=>$_GET['arid'],
				"artitle"=>$_POST['artitle'],
				"arcontent"=>$_POST['arcontent'],
			);
			if($confart->create($datas)){
				$confart->save();	
				$this->redirect('Confart/index');
			}else{
				$this->assign('erorsta','1');
				$this->assign('error',$confart->getError());
			}
		}
		$this->display();
	}
	
	//删除
	public function dele(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$arid = $_POST['arid'];
		if($arid){
			$map['arid'] = $arid;
			$res = M(Confart)->where($map)->delete();
			if($res) echo 1;
			else echo 0;
		}else{
			echo 0;
		}
	}
	
	//禁用
	public function forbidden()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$arid = $_POST['arid'];
		
		if($arid)
		{
			$map['arid'] = $arid;
			//$map["status"] = 1;
			$data["status"] = 0;
			$res = M('Confart')->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
	
	//启用
	public function enable()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$arid = $_POST['arid'];
		
		if($arid)
		{
			$map['arid'] = $arid;
			//$map["status"] = 1;
			$data["status"] = 1;
			$res = M('Confart')->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
}